﻿<UserControl
    x:Class="TfsWorkbench.PollingService.PollingServiceDialog"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:ValueConverters="clr-namespace:TfsWorkbench.UIElements.ValueConverters;assembly=TfsWorkbench.UIElements" 
    xmlns:Properties="clr-namespace:TfsWorkbench.PollingService.Properties" 
    Height="218" 
    Width="400"
    Name="PART_UserControlRoot"
    >
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/TfsWorkbench.UIElements;Component/Resources/ApplicationStyles.xaml"/>
                <ResourceDictionary Source="/TfsWorkbench.UIElements;Component/Resources/CommandButtonStyles.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            
            <ValueConverters:TimeSpanToValueConverter x:Key="TimeSpanToValueConverter" />
            <ValueConverters:BoolToStringConverter x:Key="IgnoreConflictsConverter" FalseText="No" TrueText="Yes" />
            <ValueConverters:BoolToStringConverter x:Key="ServiceStatusConverter" FalseText="Stopped" TrueText="Running" />
            <ValueConverters:TimeSpanToStringConverter x:Key="TimeSpanToStringConverter" />
            
            <Style x:Key="ReadOnlyTextBox" TargetType="TextBox">
                <Setter Property="Background" Value="#ffdcdcdc" />
                <Setter Property="IsReadOnly" Value="True" />
            </Style>
            
        </ResourceDictionary>
    </UserControl.Resources>
    <Border>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Button 
                x:Name="CloseButton" 
                Click="OnCloseButtonClick" 
                Style="{DynamicResource CloseButtonStyle}" 
                ToolTip="Close" 
                VerticalAlignment="Top"
                HorizontalAlignment="Right"
                IsCancel="True"
                />
            <TextBlock
                Style="{StaticResource DialogCaptionStyle}"
                Text="Change Polling"
                />
            <Border
                Grid.Row="1"
                Style="{StaticResource DialogInnerBorderStyle}"
                >
                <Grid DataContext="{Binding ElementName=PART_UserControlRoot, Path=ChangePoller}" VerticalAlignment="Center">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>

                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <TextBlock Text="Service Status:" VerticalAlignment="Center" />
                    <TextBlock Grid.Row="1" Text="Last Poll:" VerticalAlignment="Center" />
                    <TextBlock Grid.Row="2" Text="Next Poll In:" VerticalAlignment="Center" />
                    <TextBlock Grid.Row="3" Text="Polling Interval:" VerticalAlignment="Center" />
                    <TextBlock Grid.Row="4" Text="Ignore Change Conflicts:" VerticalAlignment="Center" />

                    <ToggleButton
                        IsChecked="{Binding Path=IsRunning, Mode=OneWay}"
                        Content="{Binding Path=IsRunning, Converter={StaticResource ServiceStatusConverter}}"
                        Click="OnServiceStatusButtonClick"
                        Width="100"
                        Grid.Column="1"
                        />

                    <TextBox
                        Name="PART_LastPoll"
                        Text="{Binding Path=LastPollTime, Mode=OneWay, StringFormat='HH:mm:ss'}"
                        Style="{StaticResource ReadOnlyTextBox}"
                        Margin="4"
                        Grid.Column="1"
                        Grid.Row="1"
                        />

                    <TextBox
                        Name="PART_NextPoll"
                        Text="{Binding Path=NextPollIn, Mode=OneWay, Converter={StaticResource TimeSpanToStringConverter}}"
                        Style="{StaticResource ReadOnlyTextBox}"
                        Margin="4"
                        Grid.Column="1"
                        Grid.Row="2"
                        />

                    <DockPanel
                        Grid.Column="1"
                        Grid.Row="3"
                        Margin="4"
                        >
                        <TextBox
                            Text="{Binding Interval}"
                            Style="{StaticResource ReadOnlyTextBox}"
                            Width="60"
                            Margin="0,0,4,0"
                            />
                        <Slider
                            Name="PART_Interval"
                            Value="{Binding Path=Interval, Converter={StaticResource TimeSpanToValueConverter}}"
                            Minimum="{Binding Source={x:Static Properties:Settings.Default}, Path=MinimumPollingInterval}"
                            Maximum="{Binding Source={x:Static Properties:Settings.Default}, Path=MaximumPollingInterval}"
                            />
                    </DockPanel>

                    <ToggleButton
                        IsChecked="{Binding Source={x:Static Properties:Settings.Default}, Path=IgnorePollingConflicts}"
                        Content="{Binding Source={x:Static Properties:Settings.Default}, Path=IgnorePollingConflicts, Converter={StaticResource IgnoreConflictsConverter}}"
                        Width="100"
                        Grid.Column="1"
                        Grid.Row="4"
                        />
                </Grid>
            </Border>
        </Grid>
    </Border>
</UserControl>
